import qs from 'qs'
import axios from 'axios'
import Vue from 'Vue'
import { baseUrl } from '../../config/base'
Vue.prototype.$http = axios

export default {
    state: {
        userMessage: ''
    },
    getters: {
        userMessage: function (state) {
          return state.userMessage
        }
    },
    mutations: {
        getUser(state,data) {
            state.userMessage = data
        }
    },
    actions: {
        getUserMessage(context,params) {

            axios.post(baseUrl + '/user/getUserInfo', qs.stringify(params),{withCredentials : true,headers:{
                'Content-Type':'application/x-www-form-urlencoded'
              }})
              .then(res=> {
                context.commit('getUser',res.data.body.data.user)
              }).catch(err=> {
              console.log(err)
            })

        },
        updatePassword(context,params) {
            return new Promise(function(resolve,reject){
                axios.post('http://localhost:3000/user/update',params)
                .then(res=>{
                    resolve(res)
                }).catch(err=> {
                    console.log(err)
                })
            })
        }
    }
}
